/**
 * 
 */
package com.locationhistory.parse;


import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.locationhistory.utils.Constants;
import com.locationhistory.utils.Logger;

/**
 * This class parser json.
 * 
 * @author thuanlv1
 * 
 */
public class JsonParser {
    /**
     * Get current location by json get form google api map.
     * 
     * @param content
     * @return
     */
    public static String parserAddressByContent(String content) {
		String address = "";
		try {
		    JSONObject json 	= new JSONObject(content);
		    String status 		= json.getString(Constants.JSON_NODE_STATUS);
	
		    if ( Constants.OK.equalsIgnoreCase(status) ) {
			JSONArray items = json.getJSONArray(Constants.JSON_NODE_RESULTS);
			if ( items.length() > 0 ) {
			    JSONObject item 	= items.getJSONObject(0);
			    address 		= item.getString(Constants.JSON_NODE_FORMATED_ADDRESS);
			} else {
			    address = Constants.TYPE_UNKNOW;
			}
		    } else {
			address = Constants.TYPE_UNKNOW;
		    }
	
		} catch (JSONException e) {
		    Logger.error(e);
	
		    address = Constants.TYPE_UNKNOW;
		}

		return address;
    } // End parserAddressByContent(String content)

}
